package org.wishwork.api.aftersale.receive.upload;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wishwork.api.Api;
import org.wishwork.api.aftersale.receive.query.AfterSaleReceivedQueryApi;
import org.wishwork.api.aftersale.receive.upload.request.AfterSaleReceiveUploadRequest;
import org.wishwork.api.aftersale.receive.upload.request.Item;
import org.wishwork.context.Context;
import org.wishwork.helper.HttpHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 实际收货上传
 * @author: WangYX
 * @create: 2022-04-12 15:13
 * @Version: 1.0.0
 **/
public class AfterSaleReceiveUploadApi extends Api<AfterSaleReceiveUploadResponse, List<AfterSaleReceiveUploadRequest>> {

    private static final Logger log = LoggerFactory.getLogger(AfterSaleReceiveUploadApi.class);

    private Context context;

    public AfterSaleReceiveUploadApi(Context context) {
        this.context = context;
    }

    @Override
    protected String query(List<AfterSaleReceiveUploadRequest> afterSaleReceiveUploadRequests) throws Exception {
        String url = "/open/refund/receive/upload";
        List<Map<String, Object>> list = new ArrayList<>();
        for (AfterSaleReceiveUploadRequest afterSaleReceiveUploadRequest : afterSaleReceiveUploadRequests) {
            Map<String, Object> params = new HashMap<>();
            params.put("as_id", afterSaleReceiveUploadRequest.getAsId());
            params.put("l_id", afterSaleReceiveUploadRequest.getLId());
            params.put("logistics_company", afterSaleReceiveUploadRequest.getLogisticsCompany());
            for (Item item : afterSaleReceiveUploadRequest.getItems()) {
                Map<String, Object> map = new HashMap<>();
                map.put("qty", item.getQty());
                map.put("sku_id", item.getSkuId());
                params.put("items", map);
            }
            list.add(params);
        }
        String biz = JSON.toJSONString(list);
        return HttpHelper.sendRequest(biz, url);
    }

    @Override
    protected AfterSaleReceiveUploadResponse process(JSONObject data, List<AfterSaleReceiveUploadRequest> afterSaleReceiveUploadRequests) throws Exception {
        return null;
    }
}
